package com.you.atlas.web.place.module.screen;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.place.service.PlaceQueryService;
import com.you.common.ibatis.data.DataList;
import com.you.place.dal.dao.constant.PlaceType;
import com.you.place.dal.dao.dataobject.PlaceDO;

public class PlaceList {

    @Autowired
    private PlaceQueryService placeQueryService;

    public void execute(@Param("pageNo") int pageNo, @Param("type") String type, @Param("id") Long id,
                        Context context, Navigator navigator) {
        PlaceDO placeDO = placeQueryService.find(id);
        if (placeDO == null) {
            navigator.redirectTo("placeModule").withTarget("error.vm");
            return;
        }
        context.put("placeDO", placeDO);
        if (placeDO.isContry()) {
            DataList cityList = placeQueryService.queryByContryId(pageNo, 20, id, PlaceType.CITY);
            DataList dataList = placeQueryService.queryByParentId(pageNo, 20, id);
            context.put("dataList", dataList);
            context.put("cityList", cityList);
        } else {
            DataList dataList = placeQueryService.queryByParentId(pageNo, 20, id);
            context.put("dataList", dataList);
        }
    }
}
